package com.tshopping.controller;

import com.tshopping.bean.DataModel;
import com.tshopping.bean.Order;
import com.tshopping.service.OrderService;
import com.tshopping.util.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

/**
 * @name: OrderController
 * @description: 订单页面控制器
 * @author: Jackeys
 * @date: 2021-01-30 16:32
 */
@RestController
@RequestMapping("/OrderController")
@CrossOrigin
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/addOrder")
    /**
     * @description 处理用户订单
     * @Param: dataModel
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-30 16:34
     */
    public ResponseData addOrder(@RequestBody DataModel dataModel) throws ParseException {
        return orderService.addOrder(dataModel);
    }
    @PostMapping(value = "/isFinishOrder")
    /**
     * @description 处理用户完成订单
     * @Param: isFinish
     * @Param: id
     * @return  ResponseData
     * @author Jackeys
     * @date 2021-01-30 16:36
     */
    public ResponseData isFinishOrder(int isFinish,int id){
        return orderService.updateIsFinishById(isFinish,id);
    }

    @PostMapping(value = "/isPayOrder")
    /**
     * @description 处理用户支付订单
     * @Param: isPay
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-30 16:39
     */
    public  ResponseData isPayOrder(@RequestBody Order order){
        return orderService.updateIsPayById(order);
    }

    @PostMapping(value = "/isSendOutOrder")
   /**
    * @description 处理商家发货
    * @Param: isSendOut
    * @Param: id
    * @return  ResponseData
    * @author Jackeys
    * @date 2021-01-30 16:41
    */
    public ResponseData isSendOutOrder(@RequestBody Order order){
        return orderService.updateIsSendOutById(order);
    }

    @PostMapping(value = "/isReceiveOrder")
    /**
     * @description 处理用户收货
     * @Param: isReceive
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-30 16:43
     */
    public ResponseData isReceiveOrder(@RequestBody Order order){
        return orderService.updateIsReceiveById(order);
    }

    @PostMapping(value = "/isRefundOrder")
    /**
     * @description 处理用户退款
     * @Param: isRefund
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-30 16:46
     */
    public ResponseData isRefundOrder(@RequestBody Order order){
        return orderService.updateIsRefundById(order);
    }

    @PostMapping(value = "/isFinishRefundOrder")
    /**
     * @description 处理用户完成退款
     * @Param: isFinishRefund
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-30 16:48
     */
    public ResponseData isFinishRefundOrder(@RequestBody Order order){
        return orderService.updateIsFinishRefundById(order);
    }

    @PostMapping(value = "/isCommentedOrder")
    /**
     * @description 处理用户是否评论
     * @Param: isCommented
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-30 16:51
     */
    public ResponseData isCommentedOrder(@RequestBody Order order){
        return orderService.updateIsCommentedById(order);
    }

    @PostMapping(value = "/getUserOrders")
    /**
     * @description 返回用户订单
     * @Param: user
     * @Param: currentPage
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-30 16:52
     */
    public ResponseData getOrdersByUser(int user,int currentPage){
        return orderService.selectOrdersByUser(user,currentPage);
    }

    @PostMapping(value="/getStoreOrders")
    /**
     * @description 返回商家订单
     * @Param: store
     * @Param: currentPage
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-30 16:53
     */
    public ResponseData getOrdersByStore(int store,int currentPage){
        return orderService.selectOrderByStore(store,currentPage);
    }

    @PostMapping(value = "updateOrderAddress")
    /**
     * @description 更新订单地址
     * @Param: address
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-30 21:08
     */
    public ResponseData updateOrderAddress(int address,int id){
        return orderService.updateAddress(address,id);
    }
    @PostMapping(value = "/isExist")
    /**
     * @description 判断订单是否存在
     * @Param: user
     * @Param: goods
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-30 21:15
     */
    public ResponseData isExist(int user,int goods){
        return orderService.isOrderExist(user,goods);
    }


    @PostMapping(value = "/record")
    /**
     * @description 保存订单
     * @Param: dataModel
     * @return 保存订单
     * @author Jackeys
     * @date 2021-01-31 08:43
     */
    public ResponseData record(DataModel dataModel){
        return orderService.record(dataModel);
    }

    @PostMapping(value = "/getOrder")
    /**
     * @description 获取订单的详细信息
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-31 14:20
     */
    public ResponseData getOrder(int id){
        return orderService.selectOrdersById(id);
    }
}
